'use strict';

import * as Koa from 'koa';
import { LogModel } from "../model/log";
import { requestlogModel } from "../model/loginfo";
import { ServiceBase } from '../kalend';

class LogService extends ServiceBase {

    constructor() {
        super(LogModel)
    }

    query(offset: number, limit: number) {
    }
    createByAppName(doc: any, appName: String = "governor") {
        return this.create(doc);
    }
    async createlog(body: any) {
        var result = await requestlogModel.create(body);
        return result
    }

    async createlogger(ctx: Koa.Context, reqtime: any){
        var contentM: any = {
            path: ctx.href,
            hostname: ctx.hostname,
            method: ctx.method,
            query: ctx.query,
            param: ctx.params,
            reqtime: reqtime,
            headers: ctx.headers,
            requestjson: ctx.request.body
        }
        if (ctx.method == "POST") {
            contentM.responsejson = ctx.response.body
        }
        await requestlogModel.create(contentM);
    }


}

export const logService = new LogService();